#include<stdio.h>
#include<stdlib.h>
#define MAX 51
typedef char ElementType;
typedef struct node* BinTree;
struct node {
    ElementType Data;
    BinTree zuo;
    BinTree you;
};
BinTree Recover(ElementType Pre[MAX], ElementType In[MAX], int len);
int GetHigh(BinTree T);
int main()
{
    BinTree Tree;
    ElementType xianxu[MAX], zhongxu[MAX];
    int N, H;
    scanf("%d%s%s", &N, xianxu, zhongxu);
    Tree = Recover(xianxu, zhongxu, N);
    H = GetHigh(Tree);
    printf("%d\n", H);
    return 0;
}
BinTree Recover(ElementType Pre[MAX], ElementType In[MAX], int len)
{
    BinTree T;
    int i;
    if (!len)
        return NULL;
    else
    {
        T = (BinTree)malloc(sizeof(struct node));
        T->Data = Pre[0];
        for (i = 0; i < len; i++)
        {
            if (Pre[0] == In[i])
                break;
        }
        T->zuo = Recover(Pre + 1, In, i);
        T->you = Recover(Pre + 1 + i, In + i + 1, len - i - 1);
    }
    return T;
}
int GetHigh(BinTree T)
{
    int l, r, max;
    if (T)
    {
        l = GetHigh(T->zuo);
        r = GetHigh(T->you);
        max = l > r ? l : r;
        return max + 1;
    }
    else
        return 0;
}